package com.lxq.live.service;

import com.lxq.live.dao.VideoRowRepository;
import com.lxq.live.pojo.VideoRow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VideoService {

    @Autowired
    VideoRowRepository videoRowRepository;

    public List<VideoRow> getBaseVideo() {
        var videoList = videoRowRepository.findAll();
        videoList.forEach((videoRow) -> videoRow.setBarrage(""));
        return videoList;
    }

    public List<VideoRow> getBaseVideoByAuthor(String authorId) {
        var videoList = videoRowRepository.findByAuthorId(authorId);
        videoList.forEach((videoRow) -> videoRow.setBarrage(""));
        return videoList;
    }

    public void updateVideoRow(VideoRow videoRow) {
        videoRowRepository.save(videoRow);
    }

    public String getBarrageByUuid(String videoUuid) {
        return videoRowRepository.getVideoBarrage(videoUuid);
    }

    public VideoRow getVideoRow(String uuid) {
        return videoRowRepository.findByUuid(uuid);
    }

    public void addVideoRow(VideoRow row) {
        videoRowRepository.save(row);
    }

    public String getVideoUrl(String uuid) {
        return videoRowRepository.findByUuid(uuid).getVideoUrl();
    }
}
